package cn.Y_Qiu.order.controller;

import cn.Y_Qiu.basic.util.Ajaxresult;
import cn.Y_Qiu.basic.util.LoginContext;
import cn.Y_Qiu.basic.util.PageList;
import cn.Y_Qiu.order.domain.AdoptOrder;
import cn.Y_Qiu.order.query.AdoptOrderQuery;
import cn.Y_Qiu.order.service.IAdoptOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;
    @PostMapping("/submit")
    public Ajaxresult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try{
            String payData = adoptOrderService.submit(params, LoginContext.currentLoginInfo(request));
            System.out.println(payData);
            return Ajaxresult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return Ajaxresult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }
    }
    @PostMapping("/admin")
    public PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery adoptOrderQuery,HttpServletRequest request){
        return adoptOrderService.admin(adoptOrderQuery,LoginContext.currentLoginInfo(request));
    }
    @PostMapping("/user")
    public PageList<AdoptOrder> user(@RequestBody AdoptOrderQuery adoptOrderQuery,HttpServletRequest request){
        return adoptOrderService.user(adoptOrderQuery,LoginContext.currentLoginInfo(request));
    }
    @GetMapping("{id}")
    public AdoptOrder getInfo(@PathVariable("id") Long id){
        return adoptOrderService.queryById(id);
    }

}
